package com.eascs.p2p.investor.dao.impl;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.springframework.stereotype.Repository;

import com.eascs.app.log.Logger;
import com.eascs.app.log.LoggerFactory;
import com.eascs.p2p.common.dao.BaseDao;
import com.eascs.p2p.common.entity.InvestorBankEntity;
import com.eascs.p2p.investor.dao.InvestorBankDao;

@Repository
public class InvestorBankDaoImpl extends BaseDao implements InvestorBankDao {
	private Logger logger = LoggerFactory.getLogger(this.getClass());

	@Override
	public int insertInvestorBank(InvestorBankEntity investorBank) {
		investorBank.setCreateTime(new Date());
		investorBank.setUpdateTime(new Date());
		return this.p2pSession.insert(investorBank);
	}

	@Override
	public int updateInvestorBank(InvestorBankEntity investorBank) {
		List<Object> param = new ArrayList<>();
		StringBuffer sql = new StringBuffer();
		sql.append("update p2p_investor_bank set ");
		if (investorBank.getBankStatus() != 0) {
			sql.append(" bank_status=?,");
			param.add(investorBank.getBankStatus());
		}
		sql.append(" update_time=?");
		param.add(new Date());
		sql.append(" WHERE id=?");
		param.add(investorBank.getId());
		return this.p2pSession.execute(sql.toString(), param.toArray());
	}

	@Override
	public InvestorBankEntity queryInvestorBankById(String id) {
		String sql="select * from p2p_investor_bank where id=?";
		return this.findEntity(sql, InvestorBankEntity.class, id);
	}

	@Override
	public InvestorBankEntity queryInvestorBankByInvestorId(String investorId) {
		String sql="select * from p2p_investor_bank where investor_id=? and bank_status=1";
		return this.findEntity(sql, InvestorBankEntity.class, investorId);
	}

}
